<template>
  <div>
    <a-dropdown>
      <a-menu slot="overlay">
        <a-menu-item
          @click="choose(index)"
          v-for="(item, index) in options"
          :key="index"
        >
          <a-icon type="user" />{{ item.text }}</a-menu-item
        >
      </a-menu>
      <a-button style="margin-left: 8px">
        {{ optionActive.text }} <a-icon type="down" />
      </a-button>
    </a-dropdown>
    <a-input-search
      v-model="searchValue"
      placeholder="请输入搜索关键字"
      style="width: 200px; margin-left: 10px"
      @search="onSearch"
    />
    <a-button @click="onSearch" style="margin-left: 10px" type="primary"> 搜索 </a-button>
    <a-button
      v-if="type == 'sample' || type == 'author'"
      @click="openAddModal"
      style="margin-left: 10px"
      type="default"
    >
      新增
    </a-button>
  </div>
</template>

<script>
export default {
  props: {
    type: {
      default: "",
      type: String,
    },
    options: {
      default: [
        {
          value: "sample",
          text: "作品集",
          ischoose: false,
        },
      ],
      type: Array,
    },
  },
  data() {
    return {
      optionActive: {},
      searchValue: "",
    };
  },
  created() {
    this.optionActive = this.options[0];
  },
  methods: {
    openAddModal() {
      this.$parent.showModal();
    },
    choose(index) {
      console.log(index);
      this.optionActive = this.options[index];
    },
    onSearch() {
      let data = {}
      data[this.optionActive.value] = this.searchValue
      this.$emit('getData',data)
      
    },
  },
};
</script>

<style>
</style>